$(function(){
	//普通用户中心免费咨询请求
	var length_url =200;
	var page = 1;
	questionSwitch()
	function questionSwitch() {
		var oDiv = $("#tab-box");
		var oLi = $("#tab-box .tabList li")
		var aCon = $("#tab-box .tabCon ul")
		var timer = null;
		for (var i = 0; i < oLi.length; i++) {
		    oLi[i].index = i;
		    oLi[i].onclick = function() {
		    	$(".tabCon .cur li").remove();
		    	$(".redtitle").remove();
		    	show(this.index);
		   }
		}
		function show(a) {
			index = a;
			var alpha = 0;
			for (var j = 0; j < oLi.length; j++) {
			    oLi[j].className = "";
			    aCon[j].className = "";
			    aCon[j].style.opacity = 0;
			    aCon[j].style.filter = "alpha(opacity=0)";
			}
			oLi[index].className = "cur";
			aCon[index].className = "cur";
			$(".comment-box").css("display","none")
			$(".item_pager .loadMore").css("display","none");
			$(".mind").css("display","none")
			$(".loadmore").attr("data-href",1);
		    switch(index){
		    	case 0:
		        	question_new(page);
		        break;
		        case 1:
		        	question_replied(page);
		        break;
		        case 2:
		        	question_toEvaluate(page);
		        break;
		        case 3:
		        	question_complete(page);
		        break;
		        case 4:
		        	question_cancelled(page);
		        break;
		    }
		    clearInterval(timer);
		    timer = setInterval(function() {
		    	alpha += 2;
		        alpha > 100 && (alpha = 100);
		        aCon[index].style.opacity = alpha / 100;
		        aCon[index].style.filter = "alpha(opacity=" + alpha + ")";
		        alpha == 100 && clearInterval(timer);
		    },5)
		}
	};
	function addTo(i) {
		var oLi = $("#tab-box .tabList li")
		$(".tabCon .cur li").remove();
    	$(".redtitle").remove();
    	$("#tab-box .tabList li").removeClass("cur").eq(i).addClass("cur");
    	if (i==0) {
    		question_new(page);
    		return false;
    	}else if(i==1){
    		question_replied(page);
    		return false;
    	}else if(i==2){
    		question_toEvaluate(page);
    		return false;
    	}else if(i==3){
    		question_complete(page);
    		return false;
    	}else if(i==4){
    		question_cancelled(page);
    		return false;
    	}
	};
	status_url(page);
	function status_url(page){
		$("#tab-box .tabList a").eq(0).attr("href",jumpUrl+"/center/question_order/"+question_type+"/new")
		$("#tab-box .tabList a").eq(1).attr("href",jumpUrl+"/center/question_order/"+question_type+"/replied")
		$("#tab-box .tabList a").eq(2).attr("href",jumpUrl+"/center/question_order/"+question_type+"/wait_for_evaluation")
		$("#tab-box .tabList a").eq(3).attr("href",jumpUrl+"/center/question_order/"+question_type+"/complete")
		$("#tab-box .tabList a").eq(4).attr("href",jumpUrl+"/center/question_order/"+question_type+"/cancelled")
		if (status_status == "new") {
    		addTo(0)
    		return false;
    	}else if(status_status == "replied"){
    		addTo(1)
    		return false;
    	}else if(status_status == "wait_for_evaluation"){
    		addTo(2)
    		return false;
    	}else if(status_status == "complete"){
    		addTo(3)
    		return false;
    	}else if(status_status == "cancelled"){
    		addTo(4)
    		return false;
    	}else if(status_status == "view"){
    		question_view();
    		return false;
    	}else{
    		window.location.href = jumpUrl+"/center/question_order/"+question_type+"/new"
    	}
	}


	//列表背景颜色
	function background_color(){
		for(var j=0; j<length_url; j++){
          if (j%2 == 0) {
          $(".tabCon .cur li").eq(j).css("background-color","#f0f0f0");
            }
        }
    };
	// 待受理
	
	function question_new (page) {
		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		url = jumpUrl+"/center/question/list?type="+question_type+"&status=new&page="+page+"&rows_per_page=10";
		$.get(url,{},function(e){
		}, 'json').error(function(data){
			var obj = $.parseJSON(data.responseText);
	        $.each(obj.error_messages, function(i, item){
		        layer.msg(item[0]);
		        stch = false;
	        });
		}).success(function(data){
			$(".loading").parent().remove();
			var obj = data.data;
			var str = '';
			if(obj.length ==0 ){
				str = '<div class="redtitle">暂时没有数据<div>';

			}
			if(obj.length>9){
				$(".item_pager .loadMore").css("display","block");
				$(".item_pager .loadMore").attr("data-id","0");
			}
			for(var i=0; i<obj.length; i++){
				str+='<li class="new-box">';
					str+='<span class="new-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
					if (question_type == "pay_company") {
						str+='<span class="new-category">&nbsp;</span>'
					}else{
						str+='<span class="new-category">'+obj[i].post_category+'</span>'
					}
					str+='<span><a href="##" data-href="'+obj[i].id+'" class="button-bg button01 js_cancel">取消</a></span>'
				str+='</li>';
			}
			$('.tabCon .cur').append(str);
			background_color();
		});
	}
	// 待确认
	function question_replied(page) {
		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		url = jumpUrl+"/center/question/list?type="+question_type+"&status=replied&page="+page+"&rows_per_page=10"
		$.get(url,{},function(e){
		}, 'json').error(function(data){
			var obj = $.parseJSON(data.responseText);
	        // $.each(obj.error_messages, function(i, item){
		       //  layer.msg(item[0]);
		       //  stch = false;
	        // });
		}).success(function(data){
			$(".loading").parent().remove();
			var obj = data.data;
			var str = '';
			if(obj.length ==0 ){
				str = '<div class="redtitle">暂时没有数据<div>';
			}
			if(obj.length>9){
				$(".item_pager .loadMore").css("display","block");
				$(".item_pager .loadMore").attr("data-id","1");
			}
			for(var i=0; i<obj.length; i++){
				str+='<li class="replied-box">';
					str+='<span class="replied-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
					if (question_type == "pay_company") {
						str+='<span class="replied-category">&nbsp;</span>'
					}else{
						str+='<span class="replied-category">'+obj[i].post_category+'</span>'
					}
					str+='<span>'
						str+='<a href="javascript:void(0)" data-id="'+obj[i].id+'" class="button-bg button01 affirm">确认</a><br>'
						str+='<a href="javascript:void(0)" data-id="'+obj[i].id+'" class="button-bg button02 to_ask">联系律师</a>'
					str+='</span>'
				str+='</li>';
			}
			$('.tabCon .cur').append(str);
			background_color();
		});
	}
	// 待评价
	function question_toEvaluate (page) {
		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		url = jumpUrl+"/center/question/list?type="+question_type+"&status=wait_for_evaluation&page="+page+"&rows_per_page=10"
		$.get(url,{},function(e){
		}, 'json').error(function(data){
			var obj = $.parseJSON(data.responseText);
	        $.each(obj.error_messages, function(i, item){
		        layer.msg(item[0]);
		        stch = false;
	        });
		}).success(function(data){
			$(".loading").parent().remove();
			var obj = data.data;
			var str = '';
			if(obj.length ==0 ){
				str = '<div class="redtitle">暂时没有数据<div>';
			}
			if(obj.length>9){
				$(".item_pager .loadMore").css("display","block");
				$(".item_pager .loadMore").attr("data-id","2");
			}
			for(var i=0; i<obj.length; i++){
				if (question_type == "question") {
					str+='<li class="evaluate-box">';
						str+='<span class="evaluate-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
						str+='<span class="evaluate-category">'+obj[i].post_category+'</span>'
						str+='<span>'
							
							str+='<a href="##" data-href="'+obj[i].id+'" class="button-bg button01 comment">评价</a><br>'
							str+='<a href="##" data-id="'+obj[i].lawyer_id+'" data-href="'+obj[i].content+'" class="button-bg button02 regard" style="background:red;">送心意</a>'
						str+='</span>'
					str+='</li>';
				}else{
					str+='<li class="evaluate-box">';
						str+='<span class="evaluate-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
						if (question_type == "pay_company") {
							str+='<span class="evaluate-category">&nbsp;</span>'
						}else{
							str+='<span class="evaluate-category">'+obj[i].post_category+'</span>'
						}
						str+='<span><a href="##" data-href="'+obj[i].id+'" class="button-bg button01 comment">评价</a></span>'
					str+='</li>';
				}
			}
			$('.tabCon .cur').append(str);
			background_color();
		});
	}
	// 已完成
	function question_complete (page) {

		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		var url = jumpUrl+"/center/question/list?type="+question_type+"&status=complete&page="+page+"&rows_per_page=10"
		$.get(url,{},function(e){
		}, 'json').error(function(data){
			var obj = $.parseJSON(data.responseText);
	        $.each(obj.error_messages, function(i, item){
		        layer.msg(item[0]);
		        stch = false;
	        });
		}).success(function(data){
			$(".loading").parent().remove();
			var obj = data.data;
			var str = '';
			if(obj.length ==0 ){
				str = '<div class="redtitle">暂时没有数据<div>';
			}
			if(obj.length>9){
				$(".item_pager .loadMore").css("display","block");
				$(".item_pager .loadMore").attr("data-id","3");
			}
			for(var i=0; i<obj.length; i++){
				if (question_type == "question"||question_type == "pay_text"){
					str+='<li class="complete-box">';
						str+='<span class="complete-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
						if (question_type == "pay_company") {
							str+='<span class="complete-category">&nbsp;</span>'
						}else{
							str+='<span class="complete-category">'+obj[i].post_category+'</span>'
						}
						str+='<span>'
							str+='<a href="'+jumpUrl+'/question/'+obj[i].id+'" class="button-bg button01">回复详情</a><br>'
							str+='<a href="##" data-id="'+obj[i].id+'" class="button-bg button02 delete-question">删除</a>'
						str+='</span>'
					str+='</li>';
				}else{
					str+='<li class="complete-box2">';
						str+='<span class="complete-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
						if (question_type == "pay_company") {
							str+='<span class="complete-category">&nbsp;</span>'
						}else{
							str+='<span class="complete-category">'+obj[i].post_category+'</span>'
						}
						str+='<span>'
							str+='<a href="##" data-id="'+obj[i].id+'" class="button-bg button01 delete-question">删除</a>'
						str+='</span>'
					str+='</li>';
				}
			}
			$('.tabCon .cur').append(str);
			background_color();
		});
	}
	// 已删除
	function question_cancelled(page) {
		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		url = jumpUrl+"/center/question/list?type="+question_type+"&status=cancelled&page="+page+"&rows_per_page=10"
		$.get(url,{},function(e){
		}, 'json').error(function(data){
			var obj = $.parseJSON(data.responseText);
	        $.each(obj.error_messages, function(i, item){
		        layer.msg(item[0]);
		        stch = false;
	        });
		}).success(function(data){
			$(".loading").parent().remove();
			var obj = data.data;
			var str = '';
			if(obj.length ==0 ){
				str = '<div class="redtitle">暂时没有数据<div>';
			}
			if(obj.length>9){
				$(".item_pager .loadMore").css("display","block");
				$(".item_pager .loadMore").attr("data-id","4");
			}
			for(var i=0; i<obj.length; i++){
				str+='<li class="cancelled-box">';
					str+='<span class="cancelled-title"><a class="view-href" data-id="'+obj[i].id+'" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/view">'+obj[i].title+'</a></span>'
					if (question_type == "pay_company") {
						str+='<span class="cancelled-category">&nbsp;</span>'
					}else{
						str+='<span class="cancelled-category">'+obj[i].post_category+'</span>'
					}
					str+='<span><a href="##" data-id="'+obj[i].id+'" class="button-bg button01 delete-question">删除</a></span>'
				str+='</li>';
			}
			$('.tabCon .cur').append(str);
			background_color();
		});
	}

	// //详情页
	// $(document).on( "click", ".view-href", function(e) {
	// 	$(".tabCon .cur li").remove();
	// 	var loading = '<li><div class="loading">加载中...</div></li>'; 
	// 	$(".tabCon .cur").append(loading);
	// 	var user_id = $(this).attr("data-id");
	// 	var url = jumpUrl+"/center/question/"+user_id+"/view"
	//     $.get(url,function(data){
	//       },'json').error(function(data) {
	//       }).success(function(data) {
	//       	$(".loading").parent().remove();
	//       	var obj = data.data
	//       	var attachments = obj.attachments
	//       	var status = obj.status
	//       	var str = ''
	//       		if (question_type == "pay_company") {
	//       			str+='<div class="view-box">'
	//       				str+='<li><span class="span1">订单编号：</span><span class="span2">'+obj.order_no+'</span></li>'
	// 					str+='<li><span class="span1">创建时间：</span><span class="span2">'+obj.created_at+'</span></li>'
	// 					str+='<li><span class="span1">订单名称：</span><span class="span2">'+obj.title+'</span></li>'
	// 					str+='<li><span class="span1">邮箱地址：</span><span class="span2">'+obj.email+'</span></li>'
	// 					str+='<li><span class="span1">企业信息：</span><span class="span2">'+obj.company_name+'</span></li>'
	// 					str+='<li><span class="span1">企业地址：</span><span class="span2">'+obj.province + obj.city + obj.district+'</span></li>'
	// 					str+='<li><span class="span1">备注信息：</span><span class="span2">'+obj.memo+'</span></li>'
	// 					str+='<li>'
	// 						str+='<p style="margin:40px 0 0 80px;">'
	// 						if (status == "new") {
	// 							str+='<a href="##" data-href="'+obj.id+'" class="button-bg js_cancel">取消</a>'
	// 						}else if(status == "replied"){
	// 							str+='<a href="##" data-id="'+obj.id+'" class="button-bg js_to_complete">确认</a>'
	// 							str+='<a href="javascript:void(0)" data-id="'+obj.id+'" class="button-bg to_ask">联系律师</a>'
	// 						}else if (status == "wait_for_evaluation") {
	// 							str+='<a href="##" data-href="'+obj.id+'" class="button-bg comment">评价</a>'
	// 						}else if (status == "complete") {
	// 							str+='<a href="##" class="button-bg">删除</a>'
	// 						}else if (status == "cancelled") {
	// 							str+='<a href="##" data-id="'+obj.id+'" class="button-bg delete-question">删除</a>'
	// 						}
	// 						str+='</p>'
	// 					str+='</li>'
	// 				str+='</div>'
	// 				$('.tabCon .cur').append(str);
	//       		}else{
	// 	            str+='<div class="view-box">'
	// 					str+='<li><span class="span1">创建时间：</span><span class="span2">'+obj.created_at+'</span></li>'
	// 					str+='<li><span class="span1">咨询标题：</span><span class="span2">'+obj.title+'</span></li>'
	// 					str+='<li><span class="span1">咨询详情：</span><span class="span2">'+obj.content+'</span></li>'
	// 					if (attachments.length !== 0) {
	// 					str+='<li><span class="span1">咨询附件：</span><span class="span2"><p>'
	// 						for (var i = 0; i < attachments.length; i++) {
	// 							str+='<a href="'+attachments[i].url+'" target="_blank"><img src="'+attachments[i].url+'" width="100" height="100" style="margin-right: 20px;"></a>'
	// 						}
	// 					}	
	// 					str+='</p></span></li>'	
	// 					str+='<li>'
	// 						str+='<p style="margin:40px 0 0 80px;">'
	// 						if (status == "new") {
	// 							str+='<a href="##" data-href="'+obj.id+'" class="button-bg js_cancel">取消</a>'

	// 						}else if(status == "replied"){
	// 							str+='<a href="##" data-id="'+obj.id+'" class="button-bg js_to_complete">确认</a>'
	// 							str+='<a href="javascript:void(0)" data-id="'+obj.id+'" class="button-bg to_ask">联系律师</a>'
	// 						}else if (status == "wait_for_evaluation") {
	// 							str+='<a href="##" data-href="'+obj.id+'" class="button-bg comment">评价</a>'
	// 						}else if (status == "complete") {
	// 							if (question_type == "question"){
	// 								str+='<a href="##" class="button-bg" style="background:red;">送心意</a>'
	// 								str+='<a href="##" class="button-bg">删除</a>'
	// 							}else{
	// 								str+='<a href="##" class="button-bg">删除</a>'
	// 							}
	// 						}else if (status == "cancelled") {
	// 							str+='<a href="##" data-id="'+obj.id+'" class="button-bg delete-question">删除</a>'
	// 						}
	// 						str+='</p>'
	// 					str+='</li>'
	// 				str+='</div>'
	// 				$('.tabCon .cur').append(str);
	// 			};
	//       });
	//       stopDefault(e);
	// })

	//详情页
	function question_view(e){
		var loading = '<li><div class="loading">加载中...</div></li>'; 
		$(".tabCon .cur").append(loading);
		var user_id = question_view_id;
		var url = jumpUrl+"/center/question/"+user_id+"/view"
	    $.get(url,function(data){
	      },'json').error(function(data) {
	      }).success(function(data) {
	      	$(".loading").parent().remove();
	      	var obj = data.data;
	      	$(".fore1_nav").addClass("curr01");
	      	$(".fore1_nav a").removeClass("curr01");
	      	$("#tab-box .tabList a li").removeClass("cur")
	      	if (obj.type== "question") {
	      		$(".fore1_nav a").eq(0).addClass("curr01");
	      	}else if (obj.type== "pay_text") {
	      		$(".fore1_nav a").eq(1).addClass("curr01");
	      	}else if (obj.type== "pay_phone") {
	      		$(".fore1_nav a").eq(2).addClass("curr01");
	      	}else if (obj.type== "pay_company") {
	      		$(".fore1_nav a").eq(3).addClass("curr01");
	      	}
	      	if (obj.status == "new") {
	    		$("#tab-box .tabList a li").eq(0).addClass("cur")
	    	}else if(obj.status == "replied"){
	    		$("#tab-box .tabList a li").eq(1).addClass("cur")
	    	}else if(obj.status == "wait_for_evaluation"){
	    		$("#tab-box .tabList a li").eq(2).addClass("cur")
	    	}else if(obj.status == "complete"){
	    		$("#tab-box .tabList a li").eq(3).addClass("cur")
	    	}else if(obj.status == "cancelled"){
	    		$("#tab-box .tabList a li").eq(4).addClass("cur")
	    	}

	      	$("#tab-box .tabList a").eq(0).attr("href",jumpUrl+"/center/question_order/"+obj.type+"/new")
			$("#tab-box .tabList a").eq(1).attr("href",jumpUrl+"/center/question_order/"+obj.type+"/replied")
			$("#tab-box .tabList a").eq(2).attr("href",jumpUrl+"/center/question_order/"+obj.type+"/wait_for_evaluation")
			$("#tab-box .tabList a").eq(3).attr("href",jumpUrl+"/center/question_order/"+obj.type+"/complete")
			$("#tab-box .tabList a").eq(4).attr("href",jumpUrl+"/center/question_order/"+obj.type+"/cancelled")

	      	var attachments = obj.attachments
	      	var status = obj.status
	      	var str = ''
	      		if (obj.type == "pay_company") {
	      			str+='<div class="view-box">'
	      				str+='<li><span class="span1">订单编号：</span><span class="span2">'+obj.order_no+'</span></li>'
						str+='<li><span class="span1">创建时间：</span><span class="span2">'+obj.created_at+'</span></li>'
						str+='<li><span class="span1">订单名称：</span><span class="span2">'+obj.title+'</span></li>'
						str+='<li><span class="span1">邮箱地址：</span><span class="span2">'+obj.email+'</span></li>'
						str+='<li><span class="span1">企业信息：</span><span class="span2">'+obj.company_name+'</span></li>'
						str+='<li><span class="span1">企业地址：</span><span class="span2">'+obj.province + obj.city + obj.district+'</span></li>'
						str+='<li><span class="span1">备注信息：</span><span class="span2">'+obj.memo+'</span></li>'
						str+='<li>'
							str+='<p style="margin:40px 0 0 80px;">'
							if (status == "new") {
								str+='<a href="##" data-href="'+obj.id+'" class="button-bg js_cancel">取消</a>'
							}else if(status == "replied"){
								str+='<a href="##" data-id="'+obj.id+'" class="button-bg js_to_complete">确认</a>'
								str+='<a href="javascript:void(0)" data-id="'+obj.id+'" class="button-bg to_ask">联系律师</a>'
							}else if (status == "wait_for_evaluation") {
								str+='<a href="##" data-href="'+obj.id+'" class="button-bg comment">评价</a>'
							}else if (status == "complete") {
								str+='<a href="##" class="button-bg">删除</a>'
							}else if (status == "cancelled") {
								str+='<a href="##" data-id="'+obj.id+'" class="button-bg delete-question">删除</a>'
							}
							str+='</p>'
						str+='</li>'
					str+='</div>'
					$('.tabCon .cur').append(str);
	      		}else{
		            str+='<div class="view-box">'
						str+='<li><span class="span1">创建时间：</span><span class="span2">'+obj.created_at+'</span></li>'
						str+='<li><span class="span1">咨询标题：</span><span class="span2">'+obj.title+'</span></li>'
						str+='<li><span class="span1">咨询详情：</span><span class="span2">'+obj.content+'</span></li>'
						if (attachments.length !== 0) {
						str+='<li><span class="span1">咨询附件：</span><span class="span2"><p>'
							for (var i = 0; i < attachments.length; i++) {
								str+='<a href="'+attachments[i].url+'" target="_blank"><img src="'+attachments[i].url+'" width="100" height="100" style="margin-right: 20px;"></a>'
							}
						}	
						str+='</p></span></li>'	
						str+='<li>'
							str+='<p style="margin:40px 0 0 80px;">'
							if (status == "new") {
								str+='<a href="##" data-href="'+obj.id+'" class="button-bg js_cancel">取消</a>'

							}else if(status == "replied"){
								str+='<a href="##" data-id="'+obj.id+'" class="button-bg js_to_complete">确认</a>'
								str+='<a href="javascript:void(0)" data-id="'+obj.id+'" class="button-bg to_ask">联系律师</a>'
							}else if (status == "wait_for_evaluation") {
								if (question_type == "question"){
									str+='<a href="##" data-href="'+obj.id+'" class="button-bg comment">评价</a>'
									str+='<a href="##" class="button-bg regard" style="background:red;">送心意</a>'
								}else{
									str+='<a href="##" data-href="'+obj.id+'" class="button-bg comment">评价</a>'
								}
							}else if (status == "complete") {
								if (question_type == "question"||question_type == "pay_text"){
									str+='<a href="'+jumpUrl+'/question/'+obj.id+'" class="button-bg button01">回复详情</a>'
									str+='<a href="##" class="button-bg">删除</a>'
								}else{
									str+='<a href="##" class="button-bg">删除</a>'
								}
							}else if (status == "cancelled") {
								str+='<a href="##" data-id="'+obj.id+'" class="button-bg delete-question">删除</a>'
							}
							str+='</p>'
						str+='</li>'
					str+='</div>'
					$('.tabCon .cur').append(str);
				};
	      });
	      stopDefault(e);
	}
	//评论
	comment()
	function comment() {
	//获取标签
		var label_url = jumpUrl+"/evaluate/tags";
		$.get(label_url,function(data){
		},'json').error(function(data){

		}).success(function(data){
			var obj = data.data;
			var str =''
			for (var i = 0; i < obj.length; i++) {
				str+='<a data-id="'+obj[i].key+'">'+obj[i].value+'</a>'
			};
			$(".comment-box .label").append(str);
			//选择标签
			$(document).ready(function(){
			  $(".comment-box .label a").toggle(
			  	function(){$(this).addClass("checked");},
			    function(){$(this).removeClass("checked");}
			  );
			});
		});
		$(document).on( "click", ".comment", function(e) {
			var id = $(this).attr("data-href");
			$(".tabCon .cur li").remove();
			$(".comment-box").css("display","block");
	        $(".comment-box .label a").removeClass("checked");
	        $(".star-icon img").attr("src",jumpUrl+"/img/star-off.png").removeClass("on");
	        $(".comment-box .textcon").val("")
		    //获取分数
		    var index = $(".star-icon img")
		    for (var i = 0; i < index.length; i++) {
			    index[i].index = i;
			    index[i].onclick = function() {
			    	imgOn(this.index);
			   }
			}
			function imgOn(a) {
				index = a;
				for (var l = 0; l < index+1 ; l++) {
					$(".star-icon img").eq(l).attr("src",jumpUrl+"/img/star-on.png").addClass("on")
				};
				for (var n = 5; n >index; n--) {
					$(".star-icon img").eq(n).attr("src",jumpUrl+"/img/star-off.png").removeClass("on")
				};
			}
		    // 提交评论
			$(document).on( "click", ".subAdvisory", function(e) {
				//获取选中的标签
				var workSope0 = $(".comment-box .label .checked").eq(0).attr("data-id");
				var workSope1 = $(".comment-box .label .checked").eq(1).attr("data-id");
				var workSope2 = $(".comment-box .label .checked").eq(2).attr("data-id");
				var workSope3 = $(".comment-box .label .checked").eq(3).attr("data-id");
				var workSope4 = $(".comment-box .label .checked").eq(4).attr("data-id");
				var workSope5 = $(".comment-box .label .checked").eq(5).attr("data-id");
				var evaluate_tags = {};
				if(workSope0){
					evaluate_tags['work_scope[0]'] = workSope0
				}
				if(workSope1){
					evaluate_tags['work_scope[1]'] = workSope1
				}
				if(workSope2){
					evaluate_tags['work_scope[2]'] = workSope2
				}
				if(workSope3){
					evaluate_tags['work_scope[3]'] = workSope3
				}
				if(workSope4){
					evaluate_tags['work_scope[4]'] = workSope4
				}
				if(workSope5){
					evaluate_tags['work_scope[5]'] = workSope5
				}
				var evaluate_score = $(".star-icon .on").length;
				var evaluate_comment = $(".comment-box .textcon").val()
				if (evaluate_score < 1) {
					layer.msg("您还没给评分");
					return false;
				}else if(evaluate_comment.length<1){
					layer.msg("请输入对律师的评价");
					return false;
				}else if(evaluate_comment.length>50){
					layer.msg("评价不能超过50字");
					return false;
				}
				evaluate_url = jumpUrl+"/center/question/"+id+"/evaluate";
				$.post(evaluate_url,{"evaluate_tags":evaluate_tags,"evaluate_score":evaluate_score,"evaluate_comment":evaluate_comment},function(data){
			        
			      },'json').error(function(data) {
			          // var obj = $.parseJSON(data.responseText);
			          // layer.msg(obj.error_messages);
			      }).success(function(data) {
			          layer.msg("评价成功");
			          $(".comment-box").css("display","none");
			          addTo(3)
			      });
			      stopDefault(e);
			});
			// 监控文本内容长度
			var text_max_length = 50
			$(".text_length").text(text_max_length)
			$(".text_bian").text(text_max_length)
			$('.textarea .textcon').bind('input propertychange', function() {
			    var content = $(".textarea .textcon").val();
			    if (content.length > 0) {
			    	$(".text_bian").text(text_max_length-content.length).css("color","#004799")
			    }else{
			      $(".text_bian").text(text_max_length-content.length).css("color","#999")
			    };
			    if(content.length == text_max_length) {
			    	$(".text_bian").text("已经最大字数").css("color","red")
			    };
			});
		});
	};

	//取消
	$(document).on( "click", ".js_cancel", function(e) {
		var loading = layer.msg('操作进行中...', {icon: 16});
		var id = $(this).attr("data-href");
		var url = jumpUrl+"/center/question/"+id+"/cancel";
	    $.post(url,{},function(data){
	      },'json').error(function(data) {
	      }).success(function(data) {
	          layer.msg("取消成功");
	          addTo(0);
	      });
	      stopDefault(e);
	});

	//删除
	$(document).on( "click", ".delete-question", function(e) {
		var loading = layer.msg('操作进行中...', {icon: 16});
		var user_id = $(this).attr("data-id");
		var $this = $(this)
		var url = jumpUrl+"/center/question/"+user_id+"/remove?captcha="+Math.random();
	    $.post(url,{},function(data){
	      },'json').error(function(data) {
	      }).success(function(data) {
	    	  $this.parent().parent().css("display","none");
	    	  layer.msg(data.data);
	      });
	      stopDefault(e); 
	});

	//联系律师
	$(document).on( "click", ".to_ask", function(e) {
		 var iTop = (window.screen.availHeight-600)/2; //获得窗口的垂直位置;
		 var iLeft = (window.screen.availWidth-715)/2; //获得窗口的水平位置;
		 id = $(this).attr("data-id");
		 chatUrl = jumpUrl+'/center/question/'+id+'/ask';
		 window.open (chatUrl, "", "height=600, width=715, top="+iTop+", left="+iLeft+", toolbar =no, menubar=no, scrollbars=no, resizable=no, location=yes, status=no");
	});
	//确认完成
	$(document).on( "click", ".js_to_complete", function(e) { 
		var loading = layer.msg('操作进行中...', {icon: 16});
		var user_id = $(this).attr("data-id");
		var url = jumpUrl+"/center/question/"+user_id+"/confirm";
	    $.post(url,{},function(data){
	      },'json').error(function(data) {
	      }).success(function(data) {
	          layer.msg(data.data);
	          layer.closeAll(); 
	          addTo(2);
	      });
	      stopDefault(e);
	});

	// // 送心意
	$(document).on('click', '.regard', function(e){
		$(".tabCon .cur li").remove();
		$(".mind").css("display","block")
		var user_id = $(this).attr("data-id");
		var product_id = $(this).parent().siblings().find(".view-href").attr("data-id");
		var subject = $(this).parent().siblings().find(".view-href").text();
		var params_body = $(this).attr("data-href");
		var wallet_url = jumpUrl+"/center/customer/wallet";
		$.get(wallet_url,function(data){},'json').success(function(data) {
			$("#money").text(data.data.money)
		});
		//选择付款方式
		$('.icon02').click(function(){
		    $('.icon02').removeClass('icon04');
		    $(this).addClass('icon04');
		});
		//付款请求
		$(document).on('click', '#js-pay', function(e){
		    var money = $("#form-money").val()
		    var type = $('.icon04').attr('data-href');
		    if (money=="") {
		    	layer.msg("请输入金额");
				return false;
		    }
		    var loading = layer.msg('加载中...', {icon: 16});
		    if (type == "wallet") {
		    	var url = jumpUrl+"/wallet/reward";
			    $.post(url,{"money":money,"user_id":user_id},function(data){
			      },'json').error(function(data) {
			          var obj = $.parseJSON(data.responseText);
			          layer.msg(obj.error_messages);
			          $(".mind").css("display","none")
			      }).success(function(data) {
			          layer.msg("送心意成功");
			          $(".mind").css("display","none")
			          $("#form-money").val("")
			          addTo(2);
			      });
		    }else{
		    	var params = {};
				params.device = 'pc';
				params.channel = 'wx_pub_qr';
				params.amount = money*100;
				params.subject = subject;
				params.body = params_body;
				params.product_id = product_id;
				params.current_user_id = current_user_id;
				params.metadata = {};
				params.metadata.pay_type = 'wallet_reward';
				params.metadata.user_id = user_id;
				params.metadata.from_user_id = from_user_id;
				var wechat_qr_params_url = jumpUrl+"/payment_gateway/charge";
				var qr_code_url = "";
			    $.post(wechat_qr_params_url,params,function(data){
			      },'json').error(function(data) {
			          var obj = $.parseJSON(data.responseText);
			          layer.msg(obj.error_messages);
			      }).success(function(data) {
				      	qr_code_url = data.credential.wx_pub_qr;
				      	charge_id = data.id;
				      	qr_payment_popup();
				      	check_payment(charge_id);
				      	var str = ''
				      		str +='<img src="http://paysdk.weixin.qq.com/example/qrcode.php?data='+qr_code_url+'" style="width:250px;height:250px;" />';
				      	    str +='<p style="text-align:center;font-size:20px;">[ 扫描二维码支付 ]</p>';
				      	$(".content-box").append(str);
			      });
		    };
		      stopDefault(e);
		});
	});
	function check_payment(charge_id){
		var t1;
		var sum =0;
		function update_notify(){
				sum++;
				if(sum>600){window.clearInterval(t1);return false;}
				if(sum>180){
					m = sum%10;
					if(m!=0){return false;}
				}
				$(".sum").html(sum);
				var payment_query_url = jumpUrl + '/payment_gateway/query/'+charge_id;
			    $.get(payment_query_url, function(data){
		        }, "json").error(function(data) {
	                var status_code = $.parseJSON(data.responseText);
	                layer.msg(status_code.message);
		        }).success(function(data) {
		            var obj = data;
		            if(obj.paid==true) {
		            	layer.msg("送心意成功");
		            	$(".mind").css("display","none")
			            $("#form-money").val("")
			            addTo(2);
			        }
		        });
			}
			t1 = window.setInterval(function() {
				popup_visible = $(".content-box").is(":visible");
				if (popup_visible) {
					update_notify();
				}
				console.log('isvisible', $(".content-box").is(":visible"));
			},1000);
		window.onblur = function(){
			clearInterval(t1);
		}
		window.onfocus = function(){
			t1 = setInterval(function(){
				popup_visible = $(".content-box").is(":visible");
				if (popup_visible) {
					update_notify();
				}
			}, 1000 );
		}
	};
	// 微信扫码付费弹出框
	function qr_payment_popup(){
	 	var Popup02 = $(".content-box");
	 	layer.open({
          type: 1, //基本层类型  可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。 若你采用layer.open({type: 1})方式调用，则type为必填项（信息框除外）
          title: false, //标题
          closeBtn: true,  //关闭按钮
          shade:0.3,  //遮罩默认是0.3透明度
          area: ['250px', '300px'],
          skin: 'yourclass', //样式类名
          content: Popup02 //内容
      	});
      	// if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
       //    $(".layui-layer").css('top','100px');
       //  }
	};
	//确认完成
	$(document).on( "click", ".affirm", function(e) {
		var user_id = $(this).attr("data-id");
		var url = jumpUrl+"/center/question/"+user_id+"/confirm";
		affirm();
		$(document).on( "click", ".js_to_complete", function(e) { 
			var loading = layer.msg('操作进行中...', {icon: 16});
		    $.post(url,{},function(data){
		      },'json').error(function(data) {
		          // var obj = $.parseJSON(data.responseText);
		          // $.each(obj.error_messages, function(i, item){
		          // });
		      }).success(function(data) {
		          layer.msg(data.data);
		          addTo(2);
		      });
		      stopDefault(e);
		});
	});
	$(document).on('click', '#js-close', function(e){
	    layer.closeAll(); 
	  });
	$(document).on( "click", ".view-href", function(e) {
		$(".item_pager .loadMore").css("display","none");
	});
	//弹出确认订单
	  function affirm(){
	    var Popup04 = $(".Popup04");
	        layer.open({
	          type: 1, //基本层类型  可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。 若你采用layer.open({type: 1})方式调用，则type为必填项（信息框除外）
	          title: false, //标题
	          closeBtn: true,  //关闭按钮
	          shade:0.3,  //遮罩默认是0.3透明度
	          area: ['300px', '120px'],
	          skin: 'yourclass', //样式类名
	          content: Popup04 //内容 
	      });
	  };
	  //滚动条拉到底部的时候去获取新的数据
	$(document).on("click",".loadMore",function(e){
		$(".item_pager .loadMore").css("display","none");
		var scroll_type = parseInt($(".loadmore").attr("data-id"));
	    var cuA = parseInt($(".loadmore").attr("data-href"));
	    $(".loadmore").attr("data-href",cuA+1);
	    var page = cuA+1;
	    if (scroll_type==0) {
    		question_new(page);
    		return false;
    	}else if(scroll_type==1){
    		question_replied(page);
    		return false;
    	}else if(scroll_type==2){
    		question_toEvaluate(page);
    		return false;
    	}else if(scroll_type==3){
    		question_complete(page);
    		return false;
    	}else if(scroll_type==4){
    		question_cancelled(page);
    		return false;
    	}
	    stopDefault(e);
	});
	
});